#include "otathread.h"

void OTAThread::run()
{
    serial = new QSerialPort();
    qDebug() << "Thread Init !!!";
    serial->setPortName(OTASerialPort); //设置串口名称和波特率
    serial->setBaudRate(QSerialPort::Baud19200);
    if (!serial->open(QIODevice::ReadWrite)) // 打开串口
    {
        QMessageBox::critical(NULL, "Error", "can't open com");
        return ;
    }
    qDebug() << "打开串口: " << OTASerialPort;

    sendYmodemFile(OTAfilePath,serial);

    while(!m_stopFlag)
    {

    }
}

void OTAThread::stop()
{
    m_stopFlag = true;
}

void OTAThread::handleMessage(const QString& filePath , const QString& SerialPort)
{
    // 在子线程中处理收到的消息
    OTAfilePath = filePath;
    OTASerialPort = SerialPort;
    qDebug() << "Received message in worker thread:" << OTAfilePath << "and" << OTASerialPort;
}
